if (allFilledUp) // drawing after allFilledUp is not allowed
return;
lastPt = localPt; // starting point of curve
didSomeDrawing = 0;
while (StillDown()) { // continue while the user holds down the mouse button
GetMouse(&nextPt); // read mouse location
if (nextPt.h < 0) // clip mouse location to make sure it is in window
nextPt.h = 0;
else if (nextPt.h > winWidth)
nextPt.h = winWidth;
if (nextPt.v < 0)
nextPt.v = 0;
else if (nextPt.v > winHeight)
nextPt.v = winHeight;
if ( (nextPt.h-lastPt.h > 1) // test if the new point is
|| (nextPt.h-lastPt.h < -1) // not too close to last point;
|| (nextPt.v-lastPt.v > 1) // this avoids storing
|| (nextPt.v-lastPt.v < -1) ) { // too many points
if (ptCount == maxPoints) {
TellUser("\pEach window can only have a certain amount of data. This window's data space is now completely filled. You can't do any more drawing in it.");
allFilledUp = 1; // out of room; stop drawing
return;
};
pt[ptCount++] = lastPt; // record a point in data array
PutLineSegment(lastPt,nextPt); // and draw the line and reflections
lastPt = nextPt;
didSomeDrawing = 1; // remember that at least one point was recorded
};
};
if (didSomeDrawing && ptCount < maxPoints)
pt[ptCount++].h = -1; // if any points were stored, put a sentinel
// in the array to separate this curve from the
// next one the user might draw (so that they
// are not connected when the window is redrawn)
}
void myWindow::doRedraw(Rect* badRect){
short i;
if (ptCount > 0) // redraw any curves entered previously by user
for (i=1; i<ptCount; i++)
if (pt[i].h != -1 && pt[i-1].h != -1) // an h value of -1 is not
PutLineSegment(pt[i-1],pt[i]); // actually on a curve; this is
// a sentinel value between curves
}
void myWindow::adjustToNewSize(void) {
Rect oldRect,newRect;
short i;
inherited::adjustToNewSize();
// Rescale the points to fit correctly into the newly resized window;
// be careful not to scale the sentinel points with h = -1 as these
// are not really points, but are only there to separate data for
// different curves. (NOTE: because coordinates are integers,
// the scaling done here involves some rounding errors, which